// pages/content/content.js
var DetailsUrl = "https://m.douban.com/rexxar/api/v2/";
Page({
  data: {
    movieDetails: [],
    card_sub: [],
    // 短评
    type: "",
    id: "",
    interests: [],
    total: 0,
    start: 0,
    count: 5
  },
  onClickLeft() {
    wx.navigateBack({
      delta: 1,
    })
  },
  onLoad: function (options) {
    //console.log(options)
    this.setData({
      type: options.type,
      id: options.id
    })
    var that = this;
    wx.request({
      url: DetailsUrl + options.type + "/" + options.id,
      success({ data }) {
        //console.log(data)
        var card = [];
        card.push(data.card_subtitle.split("/")[3], data.card_subtitle.split("/")[4])
        that.setData({
          movieDetails: data,
          card_sub: card,
        })
        // console.log(data)
      }
    });
    wx.request({
      url: DetailsUrl + options.type + "/" + options.id + "/interests",
      success({ data }) {
        // console.log(data)
        that.setData({
          interests: data.interests,
          total: data.total
        })
      }
    })
  },

  onReachBottom() {
    var that = this;
    this.setData({
      start: this.data.start + this.data.count
    });
    wx.request({
      url: DetailsUrl + this.data.type + "/" + this.data.id + "/interests?start=" + this.data.start + "&count=" + this.data.count,
      success: e => {
        that.setData({
          interests: this.data.interests.concat(e.data.interests),
        })
      }
    })
  }
})
